﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ICE.Vacations.Request;
using System.Web.Mvc;
using ICE.Vacations.DataBase;
using ICE.Vacations.Helper.Services;
using ICE.Vacations.Helper;
using System.Collections;


namespace WEBICE_4.Controllers
{
    public class HomeController : Controller
    {
       
        public ActionResult Index()
        {
            ConfigApp.LoadConfig();

            ViewBag.Message = "Modifique esta plantilla para poner en marcha su aplicación ASP.NET MVC.";  
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Página de descripción de la aplicación.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Página de contacto.";

            return View();
        }

        
        public ActionResult Solicitud() 
        {
            
            return View();
        }

        public ActionResult CrearSolicitud(FormCollection formulario)
        {
            ViewBag.Message = formulario["txtEmployeeID"].ToString();
            try
            {
                Documents doc = new Documents();
                Services.sendLog("Creando Solicitud...", Services.errorType.InformationMessage);
                doc.apellido1 = formulario["txtApellido1"].ToString();

                doc.apellido2 = formulario["txtApellido2"].ToString();

                doc.aprobador1 = formulario["txtEmployeeID"].ToString();

                doc.aprobador2 = formulario["txtEmployeeID"].ToString();

                doc.aprobador3 = formulario["txtEmployeeID"].ToString();

                doc.bossID = formulario["txtEmployeeID"].ToString();

                doc.cod_cf = formulario["txtEmployeeID"].ToString();

                doc.cod_direccion = formulario["txtEmployeeID"].ToString();

                doc.date = formulario["txtEmployeeID"].ToString();

                doc.dateFrom = formulario["txtEmployeeID"].ToString();

                doc.dateTo = formulario["txtEmployeeID"].ToString();

                doc.docUnit = formulario["txtEmployeeID"].ToString();

                doc.eMail = formulario["eMail"].ToString();

                doc.employeeID = formulario["txtEmployeeID"].ToString();

                doc.employeeName = formulario["txtemployeeName"].ToString();

                doc.managerID = formulario["txtEmployeeID"].ToString();

                doc.requestID = formulario["requestID"].ToString();

                doc.revision = formulario["txtEmployeeID"].ToString();

                doc.state = formulario["txtEmployeeID"].ToString();

                doc.tipo = formulario["txtEmployeeID"].ToString();

                doc.totalDays = Convert.ToInt32(formulario["txtEmployeeID"].ToString());

                doc.username = formulario["txtEmployeeID"].ToString();

                doc.year = formulario["txtEmployeeID"].ToString();
               
                
                doc.CreateRequest(doc);
            }
            catch (Exception exc)
            {
 
            }
            return View();
        }

        public void ComentarSolicitud()
        {
            throw new System.NotImplementedException();
        }

        public void AprovarSolicitud(Documents doc)
        {
            throw new System.NotImplementedException();
        }

        public void RechazarSolicitud(Documents doc)
        {
            throw new System.NotImplementedException();
        }

        public ActionResult ConsultarSolicitud()
        {
            return View();
        }

        //public ActionResult MostrarSolicitudes(string bossID,int page,int rows)
        //{
        //    int currentPage = Convert.ToInt32(page) - 1;
        //    int totalRecords = 0;
        //    var repository = new Documents();
        //    totalRecords = repository.SelectAll().Count;
        //    var totalPages = (int)Math.Ceiling(totalRecords / (float)rows);

        //    var jsonData = "";
        //    foreach(Documents doc in repository.SelectAll())
        //    {
        //        jsonData += new
        //        {
        //            total = totalPages,
        //        page,
        //        records = totalRecords,
        //        rows = (
        //            cell = new object[]
        //           {
        //               doc.apellido1,
        //               doc.apellido2,
        //               doc.aprobador1,
        //               doc.aprobador2,
        //               doc.aprobador3,
        //               doc.bossID,
        //               doc.cod_cf,
        //               doc.cod_direccion,
        //               doc.date,
        //               doc.dateFrom,
        //               doc.dateRegistered,
        //               doc.dateTo,
        //               doc.employeeID,
        //               doc.employeeName,
        //               doc.requestID,
        //               doc.state,
        //               doc.totalRequestedDays,
        //               doc.username

        //           }
        //        }
                  
        //        };
        //    }


        //    return Json(jsonData, JsonRequestBehavior.AllowGet);

        //    //throw new System.NotImplementedException();
        //}


    }
}
